package logic

import (
	"context"
	"video-joy/userrpc/userrpc"

	"video-joy/api/internal/svc"
	"video-joy/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateUserNameLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUpdateUserNameLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateUserNameLogic {
	return &UpdateUserNameLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UpdateUserNameLogic) UpdateUserName(req *types.UpdateUserNameRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	data, err := l.svcCtx.UserRpc.UpdateUserName(l.ctx, &userrpc.UpdateUserNameRequest{
		PhoneNum: req.PhoneNum,
		NewName:  req.NewName,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    500,
			Data:    nil,
		}, nil
	}

	return &types.Response{
		Message: "用户名称修改成功",
		Code:    200,
		Data:    data,
	}, nil
}
